package git.bankview.wl.report;

import java.util.*;
import java.text.*;
import java.io.*;

import laya.semi.process.*;

import git.bankview.sl.db.*;
import git.bankview.sl.report.ReportCommon;

import org.apache.log4j.Logger;

public class JasperStoreActivity
	implements IGenericClassActivity
{
	private static Logger log = Logger.getLogger(JasperStoreActivity.class);

	public void execute(IProcessContext oCtx)
		throws Exception
	{
		String[] params = oCtx.getActivityParameter().split(":");
		String fromField = params[0];
		String toName = params[1];
		
		String oTransid = (String)oCtx.getField("transid");
		File jasperFile = (File)oCtx.getField(fromField);
		
		if (null != jasperFile)
		{
			
			File dir = new File(ReportCommon.JASPER_DIR + oTransid);
			File dest = new File(ReportCommon.JASPER_DIR + oTransid + "/" + toName);
			if (!dir.exists())
				dir.mkdirs();
			
			if (dest.exists())
				dest.delete();
			
			if (!jasperFile.renameTo(dest))
				throw new ActivityException(oCtx, "jasperStore.err.cannotBeStored");
		}
	}
}
